package cn.toma.controller.others;

import cn.toma.common.exception.FfBootException;
import cn.toma.common.utils.web.HttpUtil;
import cn.toma.common.vo.FfBootConstant;
import cn.toma.config.web.utli.FfBootResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

@Slf4j
@Validated
@RestController
@RequestMapping("movie")
public class MovieController
{

	private String message;

	@GetMapping("hot")
	public FfBootResponse getMoiveHot() throws FfBootException
	{
		try {
			String data = HttpUtil.sendSSLPost(FfBootConstant.TIME_MOVIE_HOT_URL, "locationId=328");
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			message = "获取热映影片信息失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}

	@GetMapping("coming")
	public FfBootResponse getMovieComing() throws FfBootException
	{
		try {
			String data = HttpUtil.sendSSLPost(FfBootConstant.TIME_MOVIE_COMING_URL, "locationId=328");
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			message = "获取即将上映影片信息失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}

	@GetMapping("detail")
	public FfBootResponse getDetail(@NotBlank(message = "{required}") String id) throws FfBootException
	{
		try {
			String data = HttpUtil.sendSSLPost(FfBootConstant.TIME_MOVIE_DETAIL_URL, "locationId=328&movieId=" + id);
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			message = "获取影片详情失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}

	@GetMapping("comments")
	public FfBootResponse getComments(@NotBlank(message = "{required}") String id) throws FfBootException
	{
		try {
			String data = HttpUtil.sendSSLPost(FfBootConstant.TIME_MOVIE_COMMENTS_URL, "movieId=" + id);
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			message = "获取影片评论失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}
}
